package pl.bank.view.beans;

import java.util.Date;
import java.util.Map;

import javax.faces.event.ActionEvent;

import oracle.adf.share.logging.ADFLogger;
import oracle.adf.view.rich.component.rich.input.RichInputDate;
import oracle.adf.view.rich.component.rich.layout.RichPanelGroupLayout;
import oracle.adf.view.rich.component.rich.nav.RichCommandButton;

import oracle.binding.OperationBinding;

import utils.ADFUtils;

public class HistoryBean {
    private ADFLogger LOG = ADFLogger.createADFLogger(this.getClass().getName());
    private RichInputDate startDate;
    private RichInputDate endDate;
    private RichPanelGroupLayout historySection;

    public HistoryBean() {
        super();
    }

    public void setStartDate(RichInputDate startDate) {
        this.startDate = startDate;
    }

    public RichInputDate getStartDate() {
        return startDate;
    }

    public void setEndDate(RichInputDate endDate) {
        this.endDate = endDate;
    }

    public RichInputDate getEndDate() {
        return endDate;
    }

    public void setHistorySection(RichPanelGroupLayout historySection) {
        this.historySection = historySection;
    }

    public RichPanelGroupLayout getHistorySection() {
        return historySection;
    }

    public void showHistory(ActionEvent actionEvent) {
        OperationBinding setDates = ADFUtils.findOperation("setHistoryDates");
        Map map = setDates.getParamsMap();
        Date end = null;
        Date start = null;

        if (startDate != null && startDate.getValue() != null) {
            start = (Date)startDate.getValue();
        }
        if (endDate != null && endDate.getValue() != null) {
            end = (Date)endDate.getValue();
        }
        map.put("startDate", start);
        map.put("endDate", end);
        setDates.execute();
        historySection.setVisible(true);

    }
}
